var collectVue = new Vue({
	el: "#app",
	data: {
		empty: true,
		page: 1,
		isExcute: false,
		isBottom: false,
		friends: [],
		nextLevel:true,
		modulus:"5%"
	},
	methods: {
		handleScroll: function() {
			// 防止重复
			if (this.isExcute) {
				return;
			}
			if (this.isBottom) {
				return;
			}
			var flag = srollEvent.isReachBottom();
			if (!flag) {
				return;
			}
			this.isExcute = true;
			this.page++;
			this.show();
		},
		show: function(userId) {
			wx.showLoading({
				title: "加载中..."
			});
			this.$http.post(baseUrl + "mjz/user/query/friends", {
				currentPage: this.page,
				pageSize: 10,
				userId:userId
			}).then(function(response) {
				wx.hideLoading();
				var a = response.data;
				var s = this;
				if (!a.success) {
					wx.showToast({
						title: a.description,
						icon: "none",
						duration: 2e3,
						mask: !0
					});
				} else {
					this.empty = false;
					if (0 == a.data.length && s.page > 1) {
						s.isBottom = true;
						wx.showToast({
							title: "已经到最底下了",
							icon: "none",
							duration: 1e3,
							mask: !0
						});
					} else if (a.data.length > 0 && 1 == s.page) {
						a.data.forEach(function(e) {
							e.nextLevel = s.nextLevel;
							s.friends.push(e);
						});
					} else if (0 == a.data.length && 1 == s.page) {
						s.empty = true;
					} else {
						a.data.forEach(function(e) {
							e.nextLevel = s.nextLevel;
							s.friends.push(e);
						});
					}
				}
				this.isExcute = false;
			}).catch(function(error) {
				wx.hideLoading(), console.log(error), wx.showToast({
					title: "网络错误，请检查网络",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		toDetail:function(item){
			if(this.nextLevel){
				Jump.to(page.mine.friend,"userId="+item.userId);
			}
		}

	},
	mounted: function() {
		window.addEventListener("scroll", this.handleScroll, {
			passive: false
		});
	},
	created: function() {
		var userId = URLParam.get("userId");
		if(!userId){
			this.show();
		}else{
			this.show(userId);
			this.nextLevel = false;
			this.modulus = "3%";
		}
		
	}
});
